<template>
	<view :class="['iconfont', 'dropdown', zClass]">
		<view class="view" @click="showHandler"><slot/></view>
		<view v-if="show" class="mask" @click="showHandler"></view>
		<view v-if="show" class="con" :style="{'right': offset+'px'}">
			<view class="item" hover-class="hover" v-for="(v, i) in items" :key="i" @click="clickEvent(i)">
				<view class="label">
					<text v-if="v.icon" class="icon">{{v.icon}}</text>
					{{v.label}}
					<text v-if="v.tag">{{v.tag}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default{
		props: {
			'zClass':{type:String},
			'items':{type:Array},
			'offset':{type:null}
		},
		data(){
			return{
				show:false
			}
		},
		methods:{
			clickEvent(i){
				this.$emit('onItemClick', i)
				setTimeout(()=>{
					this.showHandler()
				}, 100)
			},
			showHandler(){
				this.show = !this.show
			}
		}
	}
</script>

<style lang="scss">
	.dropdown{
		display: flex;
		flex-direction: column;
		position: relative;
		white-space: nowrap;
		z-index: 90;
		height: 100%;
		.item{
			padding: 30upx 40upx;
			&.hover{
				background-color: rgba(0,0,0,0.03);
			}
		}
		.label{
			display: inline-flex;
			position: relative;
			align-items: center;
			line-height: 1;
		}
		.con{
			position: absolute;
			top: 100%;
			right: 0;
			background-color: #fff;
			box-shadow: 0 0 20upx rgba(0,0,0,0.1);
			border-radius: 8upx;
			z-index: 2;
		}
		.icon{
			margin-right: 10upx;
			font-size: $font-size-llg;
		}
		.view{
			height: 100%;
			display: inline-block;
		}
		.mask{
			position: fixed;
			width: 100%;
			height: 100%;
			left: 0;
			top: 0;
			z-index: 1;
		}
	}
</style>
